/**
 * @AStrutsInit.as
 * 
 * @author sodaChen mail:asframe@163.com
 * @version 1.0
 * <br>Copyright (C), 2010 asFrame.com
 * <br>This program is protected by copyright laws.
 * <br>Program Name:AStruts2
 * <br>Date:2012-4-18
 */
package com.asframe.astruts2.context
{
	import com.asframe.astruts2.beans.SystemBean;
	import com.asframe.astruts2.beans.ViewBean;
	import com.asframe.astruts2.interfaces.IInitViewEnd;
	import com.asframe.astruts2.interfaces.IInjection;
	import com.asframe.astruts2.interfaces.IRootContainer;
	import com.asframe.astruts2.metadata.MetadataConst;
	import com.asframe.collections.lists.IList;
	import com.asframe.load.multi.IMultiLoader;
	import com.asframe.loading.IMultilLoading;
	import com.asframe.pattern.observer.IObserver;
	import com.asframe.pattern.observer.ISubjects;
	import com.asframe.ref.Metadata;
	import com.asframe.ref.Variable;

	/**
	 * Astruts初始化需要的相关数据
	 * @author sodaChen
	 * @Date:2012-4-18
	 */
	public class AStrutsData
	{
		/** loading界面 **/
		public var loading						:IMultilLoading;
		/** 资源加载器接口 **/
		public var loader						:IMultiLoader;
		/** 界面操作接口 **/
	 	public var viewHandlers					:Array;
		/** 界面创建操作接口 **/
		public var viewCreateEvents				:Array;
		/** 界面中介创建操作接口 **/
		public var mediatorCreateEvents			:IList;
		/** 依赖注入的处理对象 **/
		public var injector						:IInjection;
		/** 主题集合 **/
		public var subjects						:ISubjects;
		/** Astrutst2的系统设置参数 **/
		public var systemBean					:SystemBean;
		/** AStruts2使用的根容器对象 **/
		public var root							:IRootContainer;
		/** 容器对象 **/
		public var context						:IAStrutsContext;
		/** 初始化view结束后的处理对象 **/
		public var initViewEnds					:Array;
		
		public function AStrutsData()
		{
			initViewEnds = [];
		}
		public function addInitViewEnd(initViewEnd:IInitViewEnd):void
		{
			initViewEnds.push(initViewEnd);
		}
		public function addInitViewEnds(initViewEnds:Array):void
		{
			this.initViewEnds = this.initViewEnds.concat(initViewEnds);
		}
		/**
		 * 添加一个静态的通知（延迟初始化的Mediator） 
		 * @param viewBean
		 * @param variables
		 * @param mediatorProxy
		 */		
		public function staticVarNotice(viewBean:ViewBean,variables:Array,observer:IObserver):void
		{
			if(variables == null && variables.length == 0)
			{
				return ;
			}
			var metadata:Metadata = null;
			var notice:String = null;
			for each (var variable:Variable in variables) 
			{
				//查看是否有Notice标签
				metadata = variable.getMetadata(MetadataConst.NOTICE_METADATA);
				if(metadata != null)
				{
					if(metadata.firestArg == null)
					{
						notice = variable.getValue();
					}
					else
					{
						notice = metadata.firestArg.value;
					}
					//作为主题添加观察者
					subjects.addObserver(notice,observer);
					viewBean.addObserver(notice,observer);
				}
			}
		}
	}
}
